package com.jams.rbac.controller;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jams.common.core.system.JamsResponse;
import com.jams.rbac.api.entity.Role;
import com.jams.rbac.service.RoleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;


/**
 * 系统角色表
 *
 * @author linxb
 * @date 2020-01-07 19:23:10
 */
@RestController
@AllArgsConstructor
@RequestMapping("/role")
@Api(value = "role", tags = "系统角色表管理")
public class RoleController {

    private final  RoleService roleService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param role 系统角色表
     * @return
     */
    @ApiOperation(value = "分页查询", notes = "分页查询")
    @GetMapping("/page")
    public JamsResponse getRolePage(Page page, Role role) {
        return JamsResponse.ok(roleService.page(page, Wrappers.query(role)));
    }

    /**
     * 列表查询
     * @param role 系统角色表
     * @return
     */
    @ApiOperation(value = "列表查询", notes = "列表查询")
    @GetMapping("/list")
    public JamsResponse getRoleList(Role role) {
        return JamsResponse.ok(roleService.list(Wrappers.query(role)));
    }

    /**
     * 通过id查询系统角色表
     * @param roleId id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id查询", notes = "通过id查询")
    @GetMapping("/{roleId}")
    public JamsResponse getById(@PathVariable("roleId") Long roleId) {
        return JamsResponse.ok(roleService.getById(roleId));
    }

    /**
     * 新增系统角色表
     * @param role 系统角色表
     * @return JamsResponse
     */
    @ApiOperation(value = "新增系统角色表", notes = "新增系统角色表")
    @PostMapping
    public JamsResponse save(@RequestBody Role role) {
        return JamsResponse.ok(roleService.save(role));
    }

    /**
     * 修改系统角色表
     * @param role 系统角色表
     * @return JamsResponse
     */
    @ApiOperation(value = "修改系统角色表", notes = "修改系统角色表")
    @PutMapping
    public JamsResponse updateById(@RequestBody Role role) {
        return JamsResponse.ok(roleService.updateById(role));
    }

    /**
     * 通过id删除系统角色表
     * @param roleId id
     * @return JamsResponse
     */
    @ApiOperation(value = "通过id删除系统角色表", notes = "通过id删除系统角色表")
    @DeleteMapping("/{roleId}")
    public JamsResponse removeById(@PathVariable Long roleId) {
        return JamsResponse.ok(roleService.removeById(roleId));
    }

}
